package com.gdufe.studytogether.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gdufe.studytogether.domain.R;
import com.gdufe.studytogether.domain.pojo.Group;
import com.gdufe.studytogether.service.group.GroupService;
import com.gdufe.studytogether.utils.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/group")
public class GroupController {
    @Autowired
    GroupService groupService;
    @GetMapping("/list")
    public R listGroup(Long pageSize,Long pageCurrent,Integer id,String groupName,Integer competitionId) throws Exception {
        return groupService.listGroup(pageSize,pageCurrent,id,groupName,competitionId);
    }

    @PostMapping("/add")
    public R addGroup(@RequestBody Group group) throws Exception {
        return groupService.addGroup(group);
    }

    @GetMapping("/detail")
    public R getGroupDetail(Long pageSize,Long pageCurrent,Integer id,String groupName,Integer competitionId) throws Exception {
        return groupService.getGroupDetail(pageSize,pageCurrent,id,groupName,competitionId);
    }

    @GetMapping("/delete")
    public R deleteGroup(Integer id) throws Exception {
        return groupService.deleteGroup(id);
    }


    @GetMapping("/exit")
    public R exitGroup(Integer id) throws Exception {
        return groupService.exitGroup(id);
    }

    @GetMapping("/removeMember")
    public R removeMember(Integer id,Integer uid) throws Exception {
        return groupService.removeMember(id,uid);
    }

    @PostMapping("/update")
    public R updateGroup(@RequestBody Group group) throws Exception {
        group.setStatus("0");
        return groupService.updateGroup(group);
    }
}
